<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<!-- saved from url=(0051)http://demo1.mycodes.net/denglu/HTML5_yonghudenglu/ -->
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <title>角色权限管理系统</title>
    <meta name="description" content="particles.js is a lightweight JavaScript library for creating particles.">
    <meta name="author" content="Vincent Garreau">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link rel="stylesheet" media="screen" href="${pageContext.request.contextPath}/resources/admin/login/css/style.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/resources/admin/login/css/reset.css">
<body>

<div id="particles-js">
    <div class="login" style="display: block;">
        <div class="login-top">
            登录
        </div>
        <div class="login-center clearfix">
            <div class="login-center-img"><img src="${pageContext.request.contextPath}/resources/admin/login/images/name.png"></div>
            <div class="login-center-input">
                <input id="username" type="text" name="username" value="" placeholder="请输入您的用户名" onfocus="this.placeholder=&#39;&#39;" onblur="this.placeholder=&#39;请输入您的用户名&#39;">
                <div class="login-center-input-text">用户名</div>
            </div>
        </div>
        <div class="login-center clearfix">
            <div class="login-center-img"><img src="${pageContext.request.contextPath}/resources/admin/login/images/password.png"></div>
            <div class="login-center-input">
                <input id="password" type="password" name="password" value="" placeholder="请输入您的密码" onfocus="this.placeholder=&#39;&#39;" onblur="this.placeholder=&#39;请输入您的密码&#39;">
                <div class="login-center-input-text">密码</div>
            </div>
        </div>

        <div class="login-center clearfix">
            <div class="login-center-img"><img src="${pageContext.request.contextPath}/resources/admin/login/images/password.png"></div>
            <div class="login-center-input" style="width:50%">
                <input id="cpacha" type="text" name="cpacha" value="" placeholder="请输入验证码" onfocus="this.placeholder=&#39;&#39;" onblur="this.placeholder=&#39;请输入验证码&#39;">
                <div class="login-center-input-text">验证码</div>
            </div>
            <image id="cpacha-img" title="点击切换验证码" style="cursor:pointer" src="${pageContext.request.contextPath}/system/get_cpacha?type=loginCpacha" width="100" height="30" onclick="changeCpacha()"></image>
        </div>
        <div class="login-button">
            登录
        </div>
    </div>
    <div class="sk-rotating-plane"></div>
    <canvas class="particles-js-canvas-el" width="1147" height="952" style="width: 100%; height: 100%;"></canvas></div>

<!-- scripts -->
<script src="${pageContext.request.contextPath}/resources/admin/login/js/particles.min.js"></script>
<script src="${pageContext.request.contextPath}/resources/admin/login/js/app.js"></script>
<script src="${pageContext.request.contextPath}/resources/admin/login/js/jquery.min.js"></script>
<script type="text/javascript">
    function changeCpacha() {
        $('#cpacha-img').attr('src', '${pageContext.request.contextPath}/system/get_cpacha?type=loginCpacha' + new Date().getTime());
    }

    function hasClass(elem, cls) {
        cls = cls || '';
        if (cls.replace(/\s/g, '').length == 0) return false; //当cls没有参数时，返回false
        return new RegExp(' ' + cls + ' ').test(' ' + elem.className + ' ');
    }

    function addClass(ele, cls) {
        if (!hasClass(ele, cls)) {
            ele.className = ele.className == '' ? cls : ele.className + ' ' + cls;
        }
    }

    function removeClass(ele, cls) {
        if (hasClass(ele, cls)) {
            var newClass = ' ' + ele.className.replace(/[\t\r\n]/g, '') + ' ';
            while (newClass.indexOf(' ' + cls + ' ') >= 0) {
                newClass = newClass.replace(' ' + cls + ' ', ' ');
            }
            ele.className = newClass.replace(/^\s+|\s+$/g, '');
        }
    }
    document.querySelector(".login-button").onclick = function(){
        var username = $('#username').val();
        var password = $('#password').val();
        var cpacha = $('#cpacha').val();

        if (username == '' || username == 'undefind') {
            alert('请填写用户名');
            return;
        }

        if (password == '' || username == 'undefind') {
            alert('请填写密码');
            return;
        }

        if (cpacha == '' || cpacha == 'undefind') {
            alert('请填写验证码');
            return;
        }

        $.ajax({
            url: 'login',
            data: {username: username, password:password, cpacha: cpacha},
            type: 'post',
            dataType: 'json',
            success: function(data) {

                if (data.type == 'success') {

                    confirm('登录成功');
                    window.location = '${pageContext.request.contextPath}/system/index';
                } else {
                    alert(data.msg);
                    changeCpacha();
                }
            }
        });

        // addClass(document.querySelector(".login"), "active")
        // setTimeout(function(){
        //     addClass(document.querySelector(".sk-rotating-plane"), "active")
        //     document.querySelector(".login").style.display = "none"
        // },800)
        // setTimeout(function(){
        //     removeClass(document.querySelector(".login"), "active")
        //     removeClass(document.querySelector(".sk-rotating-plane"), "active")
        //     document.querySelector(".login").style.display = "block"
        //     alert("登录成功")
        //
        // },5000)
    }
</script>
</body></html>